package com.heima.home.controller;

import com.heima.home.entity.ReviewLikes;
import com.heima.home.service.ReviewLikesService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/api/reviewLikes")
public class ReviewLikesController {

    @Autowired
    private ReviewLikesService reviewLikesService;

    /**
     * 统计点赞数
     */
    @RequestMapping("/count")
    public int countReviewLikes(Integer reviewId) {
        return reviewLikesService.countReviewLikes(reviewId);
    }
    
    /**
     * 检查用户是否已点赞
     */
    @RequestMapping("/isLiked")
    public int isLiked(@RequestBody ReviewLikes reviewLikes) {
        return reviewLikesService.isLiked(reviewLikes);
    }
    
    /**
     * 切换点赞状态（统一处理点赞和取消点赞）
     * @param reviewLikes 点赞信息
     * @return 1表示点赞成功，0表示取消点赞成功
     */
    @RequestMapping("/toggle")
    public int toggleReviewLike(@RequestBody ReviewLikes reviewLikes) {
        return reviewLikesService.toggleReviewLike(reviewLikes);
    }
}
